package com.init.iblog.controller;

import com.init.iblog.domain.ResponseResult;
import com.init.iblog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 博客文章控制层
 */
@RestController
@RequestMapping("/article")
@CrossOrigin
public class BlogController {

    @Autowired
    private BlogService blogService;


    /**
     * 查询热门博客
     * @return
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){

        System.out.println("++++++++++++++++进入/hotArticleList热门文章接口++++++++++++++++");

        ResponseResult result = blogService.hotBlogList();
        return result;
    }

    /**
     * 分页查询文章列表
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult blogListPage(Integer pageNum,Integer pageSize,Long categoryId){

        System.out.println("++++++++++++++++进入/harticleList分页查询文章列表接口++++++++++++++++");
        System.out.println("================前端传来的参数pageNum"+pageNum+"pageSize"+pageSize+"categoryId"+categoryId);
        return blogService.blogListPage(pageNum,pageSize,categoryId);
    }

    /**
     * 根据博客id查询博客，展示博客详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getBlogDetail(@PathVariable("id") Long id){

        System.out.println("++++++++++++++++进入/{id}根据博客id查询博客，展示博客详情接口++++++++++++++++");
        System.out.println("================前端传来的参数id"+id);
        return blogService.getBlogDetail(id);
    }


    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){

        System.out.println("===============进入/updateViewCount更新浏览量接口");
        System.out.println("+++++++++++++++++传递的参数id = " + id);
        return blogService.updateViewCount(id);
    }
}
